<?php
/**
 * @package Salary
 * @author Oliver Leisalu
 */
class WorkerSalary extends Salary {
	
	/**
	 * @var Float
	 */
	public $bookingCostsPerMonth = 550;
	/**
	 * @var Float
	 */
	public $otherCostsPerMonth = 150;
	
	/**
	 * Worker effectivness. It means how much time he actually earns money for company
	 * @var Float
	 */
	public $effectivness = 70;
	/**
	 * How much money is lost because of worker effectivness
	 * @var Float
	 */
	public $effectivnessLoss;
	/**
	 * How much profit company wants to make from worker salary
	 * @var Float
	 */
	public $companyProfitMarginal = 20;
	/**
	 * @var Float
	 */
	public $companyProfit;
	
	/**
	 * Real cost of employee per month
	 * @var Float
	 */
	public $totalExpenses;
	/**
	 * Real cost of employee per hour
	 * @var Float
	 */
	public $hourlyTotalExpenses;
	
	/**
	 * Estimate workdays per year. (You might set it to 12 to represent 12 months)
	 * @var Int
	 */
	public $workDaysPerYear = 260;
	/**
	 * Estimate vacation days per year. (You might set it to 1 to represent 1 month for vacation)
	 * @var Int
	 */
	public $vacationDaysPerYear = 27;
	
	
	
	/**
	 * Calculates all payments from bruto price
	 * @param Float $price
	 * @param String $type [neto|bruto|wageFund|totalExpenses]
	 */
	public function calculate( $price, $type = 'neto') {
		
		$P = 1 / (1-$this->companyProfitMarginal / 100);
		$C = $this->bookingCostsPerMonth + $this->otherCostsPerMonth;
		$D = $this->workDaysPerYear / ($this->workDaysPerYear - $this->vacationDaysPerYear);
		$F = 1/($this->effectivness/100);

		if( $type == 'totalExpenses' ) {
			$price = ( $price - $C * $D * $F ) / ($P * $D * $F);
			$type = 'wageFund';
		}
		
		if($price < 0) $price = 0;
		
		parent::calculate( $price, $type);
		
		$expenses = $this->wageFund * $P;
		$this->companyProfit = round($expenses - $this->wageFund,2);
		
		$expenses += $C; // costs
		$expenses *= $D; // workdays
		
		$e = $expenses;
		$expenses *= $F;
		$this->effectivnessLoss = round($expenses - $e,2);
		
		
		// TOTAL
		$this->totalExpenses = round($expenses,2);
		
		// HOURLY COSTS
		if( $this->workHours > 0 )
			$this->hourlyTotalExpenses = round($this->totalExpenses / $this->workHours, 2);
		else
			$this->hourlyTotalExpenses = 0;
	}
	
	
}
?>